package com.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;


 
@Configuration
public class WebConfigurer extends WebMvcConfigurationSupport {
	 @Override
	    protected void addInterceptors(InterceptorRegistry registry) {
//	        registry.addInterceptor(new LoginInterceptor()).excludePathPatterns("/loginForm");
//	        registry.addInterceptor(new LoginInterceptor()).excludePathPatterns("/getCode");
	        registry.addInterceptor(getLoginHandlerInterceptor())
	        .addPathPatterns("/user/**","/index","/toMainPage")
//	        .addPathPatterns("/**")
	        .excludePathPatterns("/getCode","/loginForm","/login");
	        super.addInterceptors(registry);
	    }

	    @Override
	    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
	        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
	        registry.addResourceHandler("/**").addResourceLocations("classpath:/log4j2.xml");
			registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0);
	        super.addResourceHandlers(registry);
	    }

	    @Override
	    protected void configureViewResolvers(ViewResolverRegistry registry) {
//	        registry.jsp("/WEB-INF/",".jsp");
	        super.configureViewResolvers(registry);
	    }
	
		   /**
	     * 提前new出 防止redis失效
	     * @return
	     */
	    @Bean
	    public LoginInterceptor getLoginHandlerInterceptor(){
	        return new LoginInterceptor();
	    }
}
